import basicTypes.C4Constant;
import Prism.core.Architecture;
import Prism.core.Component;
import Prism.core.Connector;
import Prism.core.Port;
import Prism.core.PrismConstants;
import Prism.extensions.port.ExtensiblePort;
import Prism.extensions.port.distribution.SocketDistribution;

import component.TaskProcessorGUI;

// Customer Task Terminal used for C4's representative to help customer service
public class CustomerSupportClient {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
	       Architecture customerTaskArchitecture = new Architecture();
	        
	        // Create TaskProcessorGUI Component
	    	Component taskProcessorGUIComponent = new Component();
	    	
			// Create TaskProcessorGUI Component's implementation
	    	taskProcessorGUIComponent.setImplementation(new TaskProcessorGUI());
			
			// Add a port to the TaskProcessorGUI for sending requests.
			Port taskProcessorGUIRequestPort = new Port(PrismConstants.REQUEST);
			taskProcessorGUIComponent.addPort(taskProcessorGUIRequestPort);
			
			// add TaskProcessorGUI to customerTaskArchitecture
			customerTaskArchitecture.add(taskProcessorGUIComponent);
	        
			// Create a connector(customerSupportConn) for CustomerSupport
			Connector customerSupportConnClient = new Connector();

			// Add a port to the customerSupportConn for receiving requests.
			Port customerSupportConnReplyPort = new Port(PrismConstants.REPLY);
			customerSupportConnClient.addPort(customerSupportConnReplyPort);

			// customerSupportConn is extensiblePort because a terminal of TaskProcessorGUI connects CustomerSupport by network
			ExtensiblePort customerSupportConnRequestPort = new ExtensiblePort (PrismConstants.REQUEST);
			customerSupportConnRequestPort.addDistribution(new SocketDistribution());           
			customerSupportConnClient.addPort(customerSupportConnRequestPort);
			
	        // Add the customerSupportConn to the customerTaskArchitecture
			customerTaskArchitecture.add(customerSupportConnClient);
			
			// Weld the GUI request port to the connector reply port.
			customerTaskArchitecture.weld(taskProcessorGUIRequestPort, customerSupportConnReplyPort);

			// Start the architecture.
			customerTaskArchitecture.start();

			// Connect the connector request port to the CustomerSupport.
			customerSupportConnRequestPort.connect(C4Constant.hostname, C4Constant.csPort);
		
	}
	
	
}
